if (top.location != self.location) {
	top.location=self.location;
}

$().ready( function() {
   var $copy = $(".copyright");
   var height = $(window).height();
   $copy.css("left",($(window).width()-900)/2);
   //
    if (height <= 650){
    	//
    	$(".login_logo").css({"padding-top":"30px","height":"100px"});
    }
	var $loginForm = $("#loginForm");
	var $username = $("#username");
	var $password = $("#password");
	var $captcha = $("#captcha");
	var $captchaImage = $("#captchaImage");
	var $isRememberUsername = $("#isRememberUsername");

	// 判断"记住用户名"功能是否默认选中,并自动填充登录用户名
	if($.cookie("adminUsername") != null) {
		$isRememberUsername.attr("checked", true);
		$username.val($.cookie("adminUsername"));
		$password.focus();
	} else {
		$isRememberUsername.attr("checked", false);
		$username.focus();
	}

	// 提交表单验证,记住登录用户名	
	$("#sub").click( function() {
		doup();
	});
    $(window).keydown(function(e){
    	if (e.keyCode == 13){
    		doup();
    	}
    	
    });
	// 刷新验证码	
	$captchaImage.click( function() {
		var timestamp = (new Date()).valueOf();
		var imageSrc = $captchaImage.attr("src");
		if(imageSrc.indexOf("?") >= 0) {
			imageSrc = imageSrc.substring(0, imageSrc.indexOf("?"));
		}
		imageSrc = imageSrc + "?timestamp=" + timestamp;
		$captchaImage.attr("src", imageSrc);
	});
});
$(document).ready(function(){ // 为input控件注入值

  $("input[type!='button']").each(function(){
	  var txt = $(this).attr("txt");
	  $(this).css("color","#ccc");
	  if (undefined != txt && txt != "" && $(this).val() == ""){
		  $(this).val(txt);
		  $(this).bind("focus",function(){
			  if($(this).val() == txt){
				  $(this).val("");
			  }
		  });
		  $(this).bind("blur",function(){
			  if ($(this).val() == ""){
				  $(this).val(txt);
			  }
		  });
	  }
  });	
  $("#password").focus();
});
function doup(){
	var $loginForm = $("#loginForm");
	var $username = $("#username");
	var $password = $("#password");
	var $captcha = $("#captcha");
	var $captchaImage = $("#captchaImage");
	var $isRememberUsername = $("#isRememberUsername");
	if ($username.val() == "请输入用户名") {
		alert2("请输入您的用户名!","username");
		//$username.focus();
		return false;
	}
	if ($password.val() == "") {
		alert2("请输入您的密码!","password");
		//$password.focus();
		return false;
	}
	if ($captcha.val() == "请输入验证码") {
		alert2("请输入您的验证码!","captcha");
		//$captcha.focus();
		return false;
	}
	if ($isRememberUsername.attr("checked")) {
		$.cookie("adminUsername", $username.val(), {expires:7});
	} else {
		$.cookie("adminUsername", null);
	}
	var obj = $loginForm.serialize();
	//Wloading3("登录中...");
	$("#sub").attr("disabled",true).text("登录中...");
	$.ajax({
	  type:"post",
	  url:"dologin.action",
	  data:obj,
	  success:function(data){
	   if (data.errcode == "00000"){
	     Wtip2("登录成功!!",{ok:function(){
	     window.location.href = "main.action";
	   }});
	   
	   }else{
	     alert(data.msg);
	     $("#sub").attr("disabled",false).text("立即登录");
	     
	     if(data.msg.indexOf("验证码") > -1){
	    	 var timestamp = (new Date()).valueOf();
	 		var imageSrc = $("#captchaImage").attr("src");
	 		if(imageSrc.indexOf("?") >= 0) {
	 			imageSrc = imageSrc.substring(0, imageSrc.indexOf("?"));
	 		}
	 		imageSrc = imageSrc + "?timestamp=" + timestamp;
	 		$("#captchaImage").attr("src", imageSrc);
	    	 
	     }
	   }
	   
	  }
	});
	
}